{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7,1,5,3,6,4,"
     ]
    }
   ],
   "source": [
    "#include<iostream>\n",
    "#include<vector>\n",
    "using namespace std;\n",
    "\n",
    "class Solution{\n",
    "public:\n",
    "    int maxProfit(vector<int>& prices) {\n",
    "        if (prices.empty()) return 0;\n",
    "        auto min = prices[0];\n",
    "        auto profit = 0;\n",
    "        for (auto i = 1; i < prices.size(); ++i) {\n",
    "            if (prices[i] > prices[i -1]) {\n",
    "                profit = max(profit, prices[i] - min);\n",
    "            } else {\n",
    "                min = std::min(min, prices[i]);;\n",
    "            }\n",
    "        }\n",
    "        return profit;\n",
    "    }\n",
    "};\n",
    "\n",
    "Solution solution_1;\n",
    "\n",
    "int arr[6] = {7, 1, 5, 3, 6, 4};\n",
    "\n",
    "vector<int> obj;//创建一个向量存储容器 int\n",
    "for(int i=0;i<6;i++){ // push_back(elem)在数组最后添加数据 \n",
    "    obj.push_back(arr[i]);\n",
    "    cout<<obj[i]<<\",\";\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5"
     ]
    }
   ],
   "source": [
    "#include<iostream>\n",
    "using namespace std;\n",
    "\n",
    "cout<<solution_1.maxProfit(obj);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
